package Aula04;
import java.util.Scanner;


public class Ex2 {
   
public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Write your string ");
        String str= sc.nextLine();
        System.out.println("The total of numbers in your string is " + countDigits(str));
        System.out.println("The total of spaces in your string is " +  countSpaces(str));
        System.out.println("Is your string all in lower case? " + allMin(str));
        System.out.println("Your string without double spaces: " + no2Spaces(str));
        System.out.println("Is your string a palindrome? " + palindromo(str));
    }



public static int countDigits(String s){
    int total=0;
    for(int i=0; i<s.length();i++){
        if (Character.isDigit(s.charAt(i)))
            total++;
    }
    return total;

}

public static int countSpaces(String s){
    int count=0;
    for (int i=0; i<s.length();i++){
        if (Character.isSpaceChar(s.charAt(i)))
            count++;
    }
    return count;
}

public static boolean allMin(String s){
    String strL= s.toLowerCase();
    return strL.equals(s);
}

public static String no2Spaces(String s){
    return s.trim().replaceAll(" +", " ");
}

public static Boolean palindromo(String s){

    String reverse = "";
    int length = s.length();   
    for ( int i = length - 1; i >= 0; i-- )  
       reverse += s.charAt(i);  

    return s.equals(reverse);
 }  
    
}
